import React, { lazy, Suspense } from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import Loading from '@/components/Loading';
import history from '@/utils/history';
import AuthRoute from '@/components/AuthRoute';
const Test = lazy(() => import('@/pages/Test'));
const Article = lazy(() => import('@/pages/Article'));
const Login = lazy(() => import('@/pages/Login'));
const Layout = lazy(() => import('@/pages/Layout'));
const Search = lazy(() => import('@/pages/Search'));
const Result = lazy(() => import('@/pages/Search/Result'));
const Feedback = lazy(() => import('@/pages/Profile/Feedback'));
const Edit = lazy(() => import('@/pages/Profile/Edit'));
const Chat = lazy(() => import('@/pages/Profile/Chat'));
export default function App() {
  return (
    <Router history={history}>
      <Suspense fallback={<Loading />}>
        <Switch>
          <Route path="/login" component={Login} />
          <Route path="/article/:article_id" component={Article} />
          <Route path="/search" component={Search} exact />
          <Route path="/test" component={Test} />
          <Route path="/search/result/:keyword" component={Result} />
          {/**鉴权路由 */}
          <AuthRoute path="/profile/edit" component={Edit} />
          <AuthRoute path="/profile/feedback" component={Feedback} />
          <AuthRoute path="/profile/chat" component={Chat} />
          <Route path="/" component={Layout} />
        </Switch>
      </Suspense>
    </Router>
  );
}
